Advertisement
Leon_Lejon

.functions

May 17th, 2024
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local w,h = term.getSize()
  2.  
  3. --Center Text
  4.  
  5. function printCentered (y,s)
  6.     local x = math.floor((w - string.len(s)) /2)
  7.     term.setCursorPos(x,y)
  8.     term.clearLine()
  9.     term.write(s)
  10. end
  11.  
  12. --Drawmenu
  13.  
  14. local nOption = 1
  15.  
  16. local function drawMenu()
  17.     term.setBackgroundColor(colors.cyan)
  18.     term.clear()
  19.     term.setCursorPos(1,1)
  20.     local logo = paintutils.loadImage("os/.logo")
  21.     paintutils.drawImage(logo, 1, 1)
  22.     term.setBackgroundColor(colors.cyan)
  23.    
  24.     term.setCursorPos(w-11,1)
  25.     if nOption == 1 then
  26.         term.write("DOS")
  27.     elseif nOption == 2 then
  28.         term.write("EXECUTIVE")
  29.     elseif nOption == 3 then
  30.         term.write("SHUTDOWN")
  31.     elseif nOption == 4 then
  32.         term.write("DISK")
  33.     else
  34.         end
  35. end    
  36.  
  37. --GUI
  38.  
  39. term.clear()
  40. local function drawFrontend()
  41.     printCentered(math.floor(h/2) -3, "")
  42.     printCentered(math.floor(h/2) -2, "START")
  43.     printCentered(math.floor(h/2) -1, "")
  44.     printCentered(math.floor(h/2) + 0, (nOption == 1 and "[ DOS ]") or "DOS")
  45.     printCentered(math.floor(h/2) + 1, (nOption == 2 and "[ EXECUTIVE ]") or "EXECUTIVE")
  46.     printCentered(math.floor(h/2) + 2, (nOption == 3 and "[ SHUTDOWN ]") or "SHUTDOWN")
  47.     printCentered(math.floor(h/2) + 3, (nOption == 4 and "[ DISK ]") or "DISK")
  48. end
  49.  
  50. --Display
  51.  
  52. drawMenu()
  53. drawFrontend()
  54.  
  55. while true do
  56.     local e,p = os.pullEvent()
  57.         if e == "key" then
  58.             local key = p
  59.             if key == 17 or key == 200 then
  60.            
  61.                 if nOption > 1 then
  62.                     nOption = nOption -1
  63.                     drawMenu()
  64.                     drawFrontend()
  65.                 end
  66.             elseif key == 31 or key == 208 then
  67.                 if nOption < 4 then
  68.                     nOption = nOption +1
  69.                     drawMenu()
  70.                     drawFrontend()
  71.                 end
  72.         elseif key == 28 then
  73.             break
  74. end
  75. end
  76. end
  77.  
  78. term.clear()
  79.  
  80. --Conditions
  81. if nOption == 1 then
  82.     term.setBackgroundColor(colors.black)
  83.     shell.run("os/.DOS")
  84. elseif nOption == 2 then
  85.     shell.run("os/.EXECUTIVE")
  86. elseif nOption == 3 then
  87.     shell.run("os/.SHUTDOWN")
  88. else
  89.     term.setBackgroundColor(colors.black)
  90.     term.clear()
  91.     term.setCursorPos(1,1)
  92.     print("You are now in DOS mode. Write 'back' to return to interface")
  93.     print("---------------------------------------------------")
  94.     shell.run("chkdisk")
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement